package com.xigua.字符串;

import com.xigua.util.StringUtils;

import java.util.Map;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/1023:02
 */
public class _383_赎金信 {

    public static void main(String[] args) {
        canConstruct("aa","aab");
    }

    public static boolean canConstruct(String ransomNote, String magazine) {
        if (ransomNote.length() > magazine.length()) return false;
        Map<Character, Integer> hashMap = StringUtils.countChar(magazine);
        for (int i = 0; i < ransomNote.length(); i++) {
            char key = ransomNote.charAt(i);
            if (!hashMap.containsKey(key)) return false;
            Integer value = hashMap.get(key);
            if (value > 1) {
                hashMap.put(key,value-1);}
            else {
                hashMap.remove(key);
            }
        }

        return true;
    }
}
